package com.ezops.security;

import java.util.HashMap;
import java.util.Map;

import org.apache.shiro.spring.LifecycleBeanPostProcessor;
import org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor;
import org.apache.shiro.spring.web.ShiroFilterFactoryBean;
import org.apache.shiro.web.filter.authc.PassThruAuthenticationFilter;
import org.apache.shiro.web.mgt.DefaultWebSecurityManager;
import org.apache.shiro.web.mgt.WebSecurityManager;
import org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator;
import org.springframework.beans.factory.config.MethodInvokingFactoryBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.DependsOn;

/**
 * Defines all security related configurations in spring annotation style.
 * 
 * @author vgaurav
 * 
 */
@Configuration
public class EzopsSecurityConfiguration {

//	@Bean
//	public EZOPSSecurityRealm customSecurityRealm() {
//		return new EZOPSSecurityRealm();
//	}
//
//	@Bean(name = "shiroFilter")
//	public ShiroFilterFactoryBean shiroFilter() {
//		ShiroFilterFactoryBean shiroFilter = new ShiroFilterFactoryBean();
//		shiroFilter.setSecurityManager(securityManager());
//		shiroFilter.setLoginUrl("/login");
//		shiroFilter.setSuccessUrl("/dashboard");
//		shiroFilter.setUnauthorizedUrl("/unauthorized");
//
//		Map<String, String> filterChain = new HashMap<String, String>();
//		filterChain.put("/test", "authc");
//		filterChain.put("/assets/**", "anon");
//		filterChain.put("/login", "anon");
//		shiroFilter.setFilterChainDefinitionMap(filterChain);
//		return shiroFilter;
//	}
//
//	@Bean(name = "securityManager")
//	public WebSecurityManager securityManager() {
//		DefaultWebSecurityManager securityManager = new DefaultWebSecurityManager();
//		securityManager.setRealm(customSecurityRealm());
//		return securityManager;
//	}
//
//	@Bean
//	public LifecycleBeanPostProcessor lifecycleBeanPostProcessor() {
//		return new LifecycleBeanPostProcessor();
//	}
//
//	@Bean
//	public MethodInvokingFactoryBean methodInvokingFactoryBean() {
//		MethodInvokingFactoryBean methodInvokingFactoryBean = new MethodInvokingFactoryBean();
//		methodInvokingFactoryBean
//				.setStaticMethod("org.apache.shiro.SecurityUtils.setSecurityManager");
//		methodInvokingFactoryBean
//				.setArguments(new Object[] { securityManager() });
//		return methodInvokingFactoryBean;
//	}
//
//	@Bean
//	@DependsOn(value = "lifecycleBeanPostProcessor")
//	public DefaultAdvisorAutoProxyCreator defaultAdvisorAutoProxyCreator() {
//		return new DefaultAdvisorAutoProxyCreator();
//	}
//
//	@Bean
//	public AuthorizationAttributeSourceAdvisor authorizationAttributeSourceAdvisor() {
//		AuthorizationAttributeSourceAdvisor authorizationAttributeSourceAdvisor = new AuthorizationAttributeSourceAdvisor();
//		authorizationAttributeSourceAdvisor
//				.setSecurityManager(securityManager());
//		return authorizationAttributeSourceAdvisor;
//	}
//
//	@Bean(name = "authc")
//	public PassThruAuthenticationFilter passThruAuthenticationFilter() {
//		PassThruAuthenticationFilter authFilter = new PassThruAuthenticationFilter();
//		authFilter.setLoginUrl("/login");
//		return authFilter;
//	}

}
